package com.supor.aiot.common.ui.view;

import android.content.Context;
import android.graphics.Typeface;
import android.util.TypedValue;

import net.lucode.hackware.magicindicator.buildins.ArgbEvaluatorHolder;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2021, by het, ShenZhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: IndicatorPagerTitleView <br>
 * 作者: lei <br>
 * 日期: 2021/11/5 <br>
 */
public class IndicatorPagerTitleView extends SimplePagerTitleView {
    /**
     * 选中字体是否加粗
     */
    private boolean isSelectedBold = false;
    private int selectedTextSize = 0;
    private int unselectedTextSize = 0;

    public IndicatorPagerTitleView(Context context) {
        super(context);
    }

    public void setSelectedBold(boolean selectedBold) {
        isSelectedBold = selectedBold;
    }

    public void setSelectedTextSize(int selectedTextSize) {
        this.selectedTextSize = selectedTextSize;
    }

    public void setUnselectedTextSize(int unselectedTextSize) {
        this.unselectedTextSize = unselectedTextSize;
    }

    @Override
    public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {
        int color = ArgbEvaluatorHolder.eval(leavePercent, mSelectedColor, mNormalColor);
        setTextColor(color);
        if (isSelectedBold && leavePercent == 1) {
            setTypeface(Typeface.DEFAULT);
        }
        if (unselectedTextSize != 0 && leavePercent == 1) {
            setTextSize(TypedValue.COMPLEX_UNIT_PX, unselectedTextSize);
        }
    }

    @Override
    public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {
        int color = ArgbEvaluatorHolder.eval(enterPercent, mNormalColor, mSelectedColor);
        setTextColor(color);
        if (isSelectedBold && enterPercent == 1) {
            setTypeface(Typeface.DEFAULT_BOLD);
        }
        if (selectedTextSize != 0 && enterPercent == 1) {
            setTextSize(TypedValue.COMPLEX_UNIT_PX, selectedTextSize);
        }
    }
}
